package com.gmics.unifiq.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gmics.android.R;
import com.gmics.unifiq.controller.EntityController;
import com.gmics.unifiq.controller.GooglePlace;
import com.gmics.unifiq.entity.Event;
import com.gmics.unifiq.entity.PlaceDetails;

public class ViewEventFragment extends Fragment {
	private EntityController controller = new EntityController();
	private TextView groupTV, titleTV, locationTV, dateTimeTV, descTV;
	private Event event;
	private PlaceDetails locationDetails;
	private GooglePlace googlePlace;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.view_event_layout, container,
				false);
	
		try{
			Bundle b = getActivity().getIntent().getExtras();
			event = (Event) b.getSerializable("event");
		}
		catch (Exception e){
			event = controller.retrieveLatestEvent();
		}
		
		googlePlace = new GooglePlace();
		
		try {
			locationDetails = googlePlace.getPlaceDetails(event.getLocationReference());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		groupTV = (TextView) getActivity().findViewById(R.id.group_tv);
		titleTV = (TextView) getActivity().findViewById(R.id.title_tv);
		locationTV = (TextView) getActivity().findViewById(R.id.location_tv);
		dateTimeTV = (TextView) getActivity().findViewById(R.id.date_time_tv);
		descTV = (TextView) getActivity().findViewById(R.id.desc_tv);
		
		groupTV.setText(String.valueOf(event.getGroupID()));
		titleTV.setText(event.getName());
		locationTV.setText(locationDetails.result.name);
		dateTimeTV.setText(EntityController.convertDateTimeToFullString(event.getDateTime()));
		
		return rootView;
	}


}
